package cn.hairui.fastms.core.controller;


import cn.hairui.fastms.base.config.WebLogInfo;
import cn.hairui.fastms.constant.FieldConstant;
import cn.hairui.fastms.constant.GlobalConstant;
import cn.hairui.fastms.core.annotation.TableResult;
import cn.hairui.fastms.core.bean.SDic;
import cn.hairui.fastms.core.bean.SMsg;
import cn.hairui.fastms.core.service.SMsgService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 系统消息 前端控制器
 * </p>
 *
 * @author lihairui
 * @since 2021-01-06
 */
@Controller
@RequestMapping("/sMsg")
public class SMsgController {
    @Autowired
    private SMsgService sMsgService;

    @WebLogInfo(description = "系统消息列表页面")
    @RequestMapping(value = "/list")
    public String list(HttpServletRequest request) {
        return "pages/core/smsg/smsg";
    }

    @WebLogInfo(description = "系统消息列表数据获取")
    @RequestMapping(value = "/data")
    @ResponseBody
    public TableResult data(HttpServletRequest request) {
        String pageSizeStr = request.getParameter("rows");
        String pageNumStr = request.getParameter("page");
        //String dicName = request.getParameter("dicName");
        Integer pageNum = null;
        int pageSize = GlobalConstant.DEFAULT_PAGE_SIZE;
        if (pageNumStr != null) {
            pageNum = Integer.parseInt(pageNumStr);
        }
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSizeStr != null) {
            pageSize = Integer.parseInt(pageSizeStr);
        }

        PageHelper.startPage(pageNum, pageSize);
        QueryWrapper<SMsg> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc(FieldConstant.MSG_CDE[0]);
        /*if (dicName != null && !"".equals(dicName)) {
            queryWrapper.eq(FieldConstant.DIC_NAME[0], dicName);
        }*/
        List<SMsg> sDicList = sMsgService.list(queryWrapper);
        PageInfo<SMsg> pageInfo = new PageInfo<>(sDicList);

        return new TableResult(pageInfo.getTotal(), sDicList);


    }
}

